using System;
using System.Windows;
namespace Microsoft.Expression.Media
{
	internal class DrawingPropertyMetadata : PropertyMetadata
	{
		private DrawingPropertyMetadataOptions options;
		private PropertyChangedCallback propertyChangedCallback;
		public static event EventHandler<DrawingPropertyChangedEventArgs> DrawingPropertyChanged;
		public bool AffectsRender
		{
			get
			{
				return (this.options & DrawingPropertyMetadataOptions.AffectsRender) != DrawingPropertyMetadataOptions.None;
			}
		}
		public bool AffectsMeasure
		{
			get
			{
				return (this.options & DrawingPropertyMetadataOptions.AffectsMeasure) != DrawingPropertyMetadataOptions.None;
			}
		}
		public DrawingPropertyMetadata(object defaultValue) : this(defaultValue, DrawingPropertyMetadataOptions.None, null)
		{
		}
		public DrawingPropertyMetadata(PropertyChangedCallback propertyChangedCallback) : this(DependencyProperty.UnsetValue, DrawingPropertyMetadataOptions.None, propertyChangedCallback)
		{
		}
		public DrawingPropertyMetadata(object defaultValue, DrawingPropertyMetadataOptions options) : this(defaultValue, options, null)
		{
		}
		public DrawingPropertyMetadata(object defaultValue, DrawingPropertyMetadataOptions options, PropertyChangedCallback propertyChangedCallback) : base(defaultValue, DrawingPropertyMetadata.AttachCallback(defaultValue, options, propertyChangedCallback))
		{
		}
		private DrawingPropertyMetadata(DrawingPropertyMetadataOptions options, object defaultValue) : base(defaultValue)
		{
		}
		private static PropertyChangedCallback AttachCallback(object defaultValue, DrawingPropertyMetadataOptions options, PropertyChangedCallback propertyChangedCallback)
		{
			return new PropertyChangedCallback(new DrawingPropertyMetadata(options, defaultValue)
			{
				options = options,
				propertyChangedCallback = propertyChangedCallback
			}.InternalCallback);
		}
		private void InternalCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
		{
			if (DrawingPropertyMetadata.DrawingPropertyChanged != null)
			{
				DrawingPropertyMetadata.DrawingPropertyChanged.Invoke(sender, new DrawingPropertyChangedEventArgs
				{
					Metadata = this,
					IsAnimated = sender.GetAnimationBaseValue(e.get_Property()) != e.get_NewValue()
				});
			}
			if (this.propertyChangedCallback != null)
			{
				this.propertyChangedCallback.Invoke(sender, e);
			}
		}
		static DrawingPropertyMetadata()
		{
			DrawingPropertyMetadata.DrawingPropertyChanged += delegate(object sender, DrawingPropertyChangedEventArgs e)
			{
				IShape shape = sender as IShape;
				if (shape != null && e.Metadata.AffectsRender)
				{
					InvalidateGeometryReasons invalidateGeometryReasons = InvalidateGeometryReasons.PropertyChanged;
					if (e.IsAnimated)
					{
						invalidateGeometryReasons |= InvalidateGeometryReasons.IsAnimated;
					}
					shape.InvalidateGeometry(invalidateGeometryReasons);
				}
			};
		}
	}
}
